Permission : Permission control

更新时间:
2024-05-15
下载文档

Permission : Permission control

This module is EdgerOS permission check and asynchronous reminder module. This module is available in EdgerOS 1.6.0 and later.

This module is the asynchronous mode of the permission module. User can use the following code to import the permission module.

var permission = require('async/permission');

Support

The following shows permission module APIs available for each permissions.

 User ModePrivilege Mode
permission.update
permission.check
permission.device
permission.fetch
permission.isDenied

Permission Introduction

EdgerOS application permissions are a tree structure, stored in an object, and App can check whether they have this permission by checking related properties.

EdgerOS permission tree object contains the following members:

  • ainn {Boolean} Whether AI Neural Network Computing is allowed.
  • alarm {Boolean} Is there permission to add alarms.
  • share {Boolean} Does this app allow sharing of information with other apps.
  • notify {Boolean} Whether this app allows push messages.
  • advnwc {Boolean} Whether this app allows advanced network control.
  • network {Boolean} Whether this app allows network communication.
  • display {Boolean} Whether this app allows use display output.
  • rtsp {Boolean} Whether this app allows RTSP network such as: Webcam, Network microphone.
  • lora {Boolean} Whether this app allows send or receive data via LoRaWAN network.
  • coap {Boolean} Whether this app allows CoAP IoT network protocol.
  • wallpaper {Boolean} Whether this app allows set wallpaper.
  • account {Boolean} Whether to allow get the user list and group list.
  • printer {Boolean} Whether this app allows to use printer.
  • auxstorage {Boolean} Whether this app allows to use auxiliary storage.
  • vpn {Boolean} Whether this app allows to create and manage VPN networks (temporarily closed).
  • mqtt {Object} MQTT Client sub object.
    • publish {Boolean} Whether to allow applications to publish data using the MQTT protocol.
    • subscribe {Boolean} Whether to allow applications to subscribe to messages using MQTT protocol.
  • mediacenter {Object} Media Center access permission.
    • readable {Boolean} Can read media center content.
    • writable {Boolean} Can write media center content.
    • removable {Boolean} Can remove media center content.
  • vehicle {Object} Vehicle features.
    • media {Boolean} Audio-visual entertainment system.
    • geolocation {Boolean} Vehicle geolocation.
    • diagnostic {Boolean} Vehicle diagnostic information.
    • cockpit {Boolean} Cockpit controls, such as air conditioning, car windows.
    • drive {Boolean} Driving and autonomous driving related functions.
  • devices {Array} List of allowed device IDs.

Permission Functions

permission.update(callback)

  • callback {Function} This callback function will be called when the current application has permission to change.
    • perm {Object} New complete permission table including devices.

Install a permission change callback function.

Example

permission.update(function(perm) {
  console.log('Current App permissions are changed.');
});

async permission.check(permChk)

  • permChk {Object} Need to determine the permission object.
  • Returns: {Boolean} Whether the current application has the specified permissions.

Checks if the application has the specified permissions.

Example

async function check() {
  var res = await permission.check({
    share: true, mqtt: { subscribe: true }
    });
  if (res) {
      console.log('We have share and Mqtt subscribe permissions');
  }
}

async permission.device(devid)

  • devid {String} Device ID.
  • Returns: {Boolean} Whether the current application has the specified device operate permissions.

Checks if the application has the specified device operate permissions.

Example

async function checkDev() {
  var res = await permission.device(devid);
  if (res) {
    console.log('We have this device permissions');
  }
}

async permission.fetch()

  • Returns: {Object} Complete permission table including devices.

Fetch the current App permissions.

Example

permission.fetch().then(perm => {
  console.log(JSON.stringify(perm));
}).catch(console.error);

permission.isDenied(error)

  • error {String | Error} Error.
  • Returns: {String} Is this error a permission denied error.

Determine whether the error message is a permission denied error message.

Example

var Device = require('async/device');

async function createDev(devid) {
  var dev = new Device();
  try {
    await dev.request(devid);
  } catch (error) {
    if (permission.isDenied(error)) {
      console.log('No permission....');
    }
    return;
  }
  return dev;
}
文档内容是否对您有所帮助?
有帮助
没帮助